#!/usr/bin/python3
# -*- coding: utf-8 -*-

try:
  exec(open("import_qt.py").read())
except FileNotFoundError:
  print("You need to copy import_pyqt5.py or import_pyside.py to import_qt.py")
  exit()
import sys
from guiHandler import JsHandler
from record import Recorder
from ringBuffer import RingBuffer
from volumeMeter import VolumeMeter


def main():

  app = QApplication(sys.argv)

  w = QWebView()
  f = QFileInfo("html/gui.html")
  w.load(QUrl.fromLocalFile(f.absoluteFilePath()))


  frame = w.page().mainFrame()

  classCt = {}
  classCt["buffer"] = RingBuffer(100000)
  classCt["jsHandler"] = JsHandler(frame, classCt)
  classCt["statusListeners"] = [classCt["jsHandler"].statusChanged]
  classCt["audioRec"] = Recorder(classCt["buffer"], \
                                 classCt["jsHandler"].logMsg, \
                                 classCt["statusListeners"], \
                                 app)
  classCt["volumeMeter"] = VolumeMeter(classCt["buffer"], \
                                       None)


  w.loadFinished.connect(classCt["jsHandler"].loaded)
  w.resize(600,300)

  w.show()

  w.page().settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
  inspector = QWebInspector();
  inspector.setPage(w.page());
  #inspector.show();

  sys.exit(app.exec_())


if __name__ == '__main__':
    main()
